# Contributor: Valery Kartel <valery.kartel@gmail.com>
# Maintainer: Valery Kartel <valery.kartel@gmail.com>
pkgname=capstone
pkgver=4.0.2
pkgrel=0
pkgdesc="The Ultimate Disassembler"
options="!check" # Testsuite fails
url="https://www.capstone-engine.org"
arch="all"
license="BSD-3-Clause-Clear"
depends_dev="$pkgname"
makedepends="bash py3-setuptools cython python3-dev"
subpackages="$pkgname-static $pkgname-dev py3-${pkgname}:_py3 cstool"
source="$pkgname-$pkgver.tar.gz::https://github.com/aquynh/capstone/archive/$pkgver.tar.gz
	py-path-fix.patch"

build() {
	CFLAGS="$CFLAGS -O2" make
}

check() {
	make check
}

package() {
	make PREFIX=/usr DESTDIR="$pkgdir" install
}

_py3() {
	pkgdesc="$pkgdesc (for python3)"
	install_if="$pkgname=$pkgver-r$pkgrel python3"

	cd "$builddir"/bindings/python
	python3 setup_cython.py install --prefix=/usr --root="$subpkgdir"

	rm -rf "$subpkgdir"/usr/lib/python3*/site-packages/capstone/lib
	rm -rf "$subpkgdir"/usr/lib/python3*/site-packages/capstone/include
}

cstool() {
	pkgdesc="cstool for capstone disassembler"

	mkdir -p "$subpkgdir"/usr/bin
	mv "$pkgdir"/usr/bin/cstool "$subpkgdir"/usr/bin
}

sha512sums="7f93534517307b737422a8825b66b2a1f3e1cca2049465d60ab12595940154aaf843ba40ed348fce58de58b990c19a0caef289060eb72898cb008a88c470970e  capstone-4.0.2.tar.gz
e9a2d7cb391285890872123fb3e5ae8f8cde6e4f858c31f5c815c110f6c6d5ec86cef4920b277d5630745a34a268e52b402855429b072f0b5a722d6a610366a8  py-path-fix.patch"
